#include "MockInterface.h"

MockInterface::MockInterface()
{

}

void MockInterface::activeTestMock(){
    emit testMock(123);
}

QVariantList MockInterface::getProgramInfo(QString){
    qDebug() << "MOCK" << __FUNCTION__;
    QVariantList list;
    for(int i = 0; i < 10; i ++){
        QVariantMap lmap;
        lmap["Id"] = QString::number(i);
        lmap["IsDefault"] = true;
        lmap["ProgramName"] = "程序" + QString::number(i);
        list.append(lmap);
    }
    return list;
}


int MockInterface::deleteProgramInfo(QString){
    qDebug() << "MOCK" << __FUNCTION__;
    return 0;
}


int MockInterface::deleteAllProgramInfo(){
    qDebug() << "MOCK" << __FUNCTION__;
    return 0;
}


int MockInterface::setDefaultProgram(QString, QString){
    qDebug() << "MOCK" << __FUNCTION__;
    return 0;
}

QVariantList MockInterface::getProgramStepInfo(QString){
    qDebug() << "MOCK" << __FUNCTION__;
    QVariantList res;
    return res;
}

QString MockInterface::saveProgramInfo(QVariantMap, QVariantList){
    qDebug() << "MOCK" << __FUNCTION__;
    return "1";
}


QVector<QVector<QPointF>> MockInterface:: getChartInfo(int equId, QString accessInfo, QString posInfo){
    qDebug() << "MOCK" << __FUNCTION__;
    QVector<QVector<QPointF>> res;

    qsrand(QTime::currentTime().msec());
    for(int i = 0; i < 2; i ++){
        QVector<QPointF> list;
        for(int c = 0; c < 40; c ++){
            list.append(QPointF(c, qrand() % 100));
        }
        res.push_back(list);
    }

    return res;
}

QMap<QString, QVariantList> MockInterface::getBarChartInfo(int eqId, QString accessInfo, QString posiInfo){
    qDebug() << "MOCK" << __FUNCTION__;
    QMap<QString, QVariantList> res;

    QVariantList list1;
    QVariantList list2;
    QVariantList list3;
    QVariantList list4;
    QVariantList list5;

    qsrand(QTime::currentTime().msec());
    for(int i = 0; i < 30; i ++){
        list1.push_back("A" + QString::number(i));
        list2.push_back(qrand() % 10);
        list3.push_back(qrand() % 10);
        list4.push_back(qrand() % 10);
        list5.push_back(qrand() % 10);
    }

    res["posi"] = list1;
    res["FAM"] = list2;
    res["VIC"] = list3;
    res["ROX"] = list4;
    res["CY5"] = list5;


    /*
    Map{

        "posi": [A1, A2, A3, A4],
        "FAM": [1, 2, 3, 4],
        "VIC": [4, 6, 3, 5],
        "ROX": [4, 6, 3, 5],
        "CY5": [4, 6, 3, 5],

    }
    */


    return res;
}


QVariantMap MockInterface::getOtherInfo(QString){
    QVariantMap rmap;
    qsrand(QTime::currentTime().msec());
    rmap["Temp"] = qrand() % 100;
    rmap["Cycle"] = qrand()%40;
    rmap["CycleNum"] = 42;
    rmap["Step"] = qrand()%4+1;
    return rmap;
}

void MockInterface::appendChild(){

    QObject *pRoot = engine->rootObjects().first();

    QQuickItem *target = pRoot->findChild<QQuickItem *>("PCRChart");

    if(!target){
        qDebug() << "未找到对应元素";
        return;
    }
    qDebug() << "定位成功";


    QQuickWindow* qmlwindow = qobject_cast<QQuickWindow *>(engine->rootObjects().first());


    QWidget* widget = new QWidget();
    QHBoxLayout* layout = new QHBoxLayout(widget);
    widget->setLayout(layout);
    layout->addWidget(new QLabel("AA", widget));
    widget->setGeometry(target->x(), target->y(), target->width(), target->height());

    QWindow* widgetWindow = QWindow::fromWinId(widget->winId());
    widgetWindow->setParent(qmlwindow);
    widget->show();

    new WidgetAnchor(widget, target);
}
